import { CopyControllerBase } from "./CopyControllerBase";
import { SixtyCopyView } from "../sixty/SixtyCopyView";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ECmdCell } from "../../../../../Message/Command/ECmdCell";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SSeqPlayerItem } from "../../../../../Message/Public/SSeqPlayerItem";
import { DataEvent } from "../../../events/DataEvent";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { SPassPoint } from "../../../../../Message/Public/SPassPoint";
import { SPassTo } from "../../../../../Message/Public/SPassTo";
import { GameProxy } from "../../../mvc/GameProxy";
import { EPassType } from "../../../../../Message/Game/EPassType";
import { Language } from "../../../../../extend/language/Language";
import { MsgManager } from "../../../manager/MsgManager";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
type int = number;
//class SixtyCopyController
    
    export  class SixtyCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        public get sixtyCopyView(): SixtyCopyView
        {
            if (!this._sixtyCopyView) 
            {
                this._sixtyCopyView = new SixtyCopyView();
            }
            return this._sixtyCopyView;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ECmdCell._ECmdCellPushSixtyItemList, this.onReceiveSixtyItemList);
            NetDispatcher.addCmdListener(ECmdCell._ECmdCellBossClear, this.onSixtyFirstFloorBossClear);
            Dispatcher.addEventListener(EventName.CopySixtyLeaveFirstFloor, this.onSixtyLeaveFirstFloor);
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            this.showSixtyPropPanel();
            Dispatcher.addEventListener(EventName.ChangeScene, this.onChangeSceneHandler);
            return;
        }

        /* internal  */onChangeSceneHandler(arg1): void
        {
            if (this._sixtyCopyView) 
            {
                this._sixtyCopyView.updateView();
            }
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            if (this._sixtyCopyView && !this._sixtyCopyView.isHide) 
            {
                this._sixtyCopyView.hide();
            }
            Dispatcher.addEventListener(EventName.ChangeScene, this.onChangeSceneHandler);
            return;
        }

        public /* override */ stageResize(): void
        {
            if (this._sixtyCopyView) 
            {
                this._sixtyCopyView.stageResize();
            }
            return;
        }

        /* internal  */showSixtyPropPanel(): void
        {
            if (cache.copy.isInSixtyCopy()) 
            {
                this.sixtyCopyView.show();
                this.stageResize();
            }
            return;
        }

        /* internal  */onReceiveSixtyItemList(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSeqPlayerItem;
            cache.copy.sixtyCopyItems = loc1.playerItem;
            this.sixtyCopyView.updateItems();
            return;
        }

        /* internal  */onSixtyLeaveFirstFloor(arg1: DataEvent): void
        {
            var e: DataEvent;
            var close: Function;

            var loc1;
            close = null;
            e = arg1;
            close = (arg1: int): void
            {
                var loc1=null;
                var loc2=null;
                if (arg1 == Alert.YES) 
                {
                    loc1 = e.data as SPassPoint;
                    loc2 = loc1.passTo[0] as SPassTo;
                    if (loc2) 
                    {
                        GameProxy.sceneProxy.pass(EPassType.convert(EPassType._EPassTypeByPassPoint), loc1.passPointId, loc2.passToId);
                    }
                }
                return;
            }
            if (cache.copy.sixtyFirstFloorBossCleared) 
            {
                close(Alert.YES);
            }
            else 
            {
                Alert.show(Language.getString(60033), Language.getString(69900), Alert.YES | Alert.NO, null, close);
            }
            return;
        }

        /* internal  */onSixtyFirstFloorBossClear(arg1: MessageBlock): void
        {
            var loc2=0;
            var loc3=0;
            if (cache.copy.sixtyInWhichFloor() != 1) 
            {
                return;
            }
            cache.copy.sixtyFirstFloorBossCleared = true;
            MsgManager.showTaskTarget(Language.getString(60034));
            var loc1=cache.scene.getNearlyPassPoint(false);
            if (loc1) 
            {
                loc2 = loc1.point.x;
                loc3 = loc1.point.y;
                RolePlayer.instance.setTargetTilePoint(loc2, loc3);
                Dispatcher.addEventListener(EventName.ChangeScene, this.onSixtyCopyChangeSceneHandler);
            }
            return;
        }

        /* internal  */onSixtyCopyChangeSceneHandler(arg1: DataEvent): void
        {
            RolePlayer.instance.removeTargetTilePoint();
            Dispatcher.removeEventListener(EventName.ChangeScene, this.onSixtyCopyChangeSceneHandler);
            return;
        }

        /* internal */ /* var */_sixtyCopyView: SixtyCopyView;
    }
